<template>
  <div>
    <el-button type="primary" @click="willAdd">添加</el-button>
    <v-list :list="list" @init="init" @edit="willEdit"></v-list>
    <v-form :info="info" :list="list" @init="init" ref="form"></v-form>
  </div>
</template>
<script>
import vList from "./component/list";
import vForm from "./component/form";
import { mapGetters, mapActions } from "vuex";
import { reqrolelist } from '../../request/api';
export default {
  props: [],
  components: {
    vList,
    vForm,
  },
  data() {
    return {
        info:{
            isshow:false,
            isAdd:true
        },
        list:[],
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {
         this.init();
  },
  methods: {
    ...mapActions({}),
    //点了添加
    willAdd(){
        this.info.isshow=true
        this.info.isAdd=true
    },
    //点了编辑
    willEdit(id){
        this.info.isshow=true
        this.info.isAdd=false
        //通知form取数据
      this.$refs.form.getOne(id)
    },
    //进去列表
    init(){
        reqrolelist().then((res)=>{
            if (res.data.code == 200) {
          this.list = res.data.list ? res.data.list : [];
        }
        })
    }
  },
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
</style>